var mon_category_id;
$(function () {
    $('#dg').datagrid({
        method: "get",
        url: getRootPath() + '/mtManage/assets/list_monthlyGrid',
        fit: true,
        border: true,
        idField: 'mon_category_id',
        striped: false,
        pagination: true,
        rownumbers: true,
        pageNumber: 1,
        pageSize: 20,
        pageList: [10, 20, 30, 50, 100],
        singleSelect: true,
        checkOnSelect: true,
        toolbar: '#tb',
        fitColumns: true,
        loadMsg: "数据加载中",
        columns: [[
            {field: 'ck', checkbox: true},
            {field: 'content_description', title: '内容描述', width: 100},
            {field: 'dept_group', title: '部门组别', width: 100},
            // {field: 'floor_workshop', title: '楼层车间', width: 100},
            {field: 'completed_by', title: '填写人', width: 100},
            {field: 'complete_time', title: '填写时间', width: 100}
        ]],
        onDblClickRow: function (index, row) {
            operator_apply(row);
        },
        queryParams: {
            username: username
        }
    });
});

//月度申请查询
function queryMonthlyAssets() {
    $('#assets-dg_mon').datagrid('uncheckAll');
    $('#assets-dg_mon').datagrid('reload', {
        mon_date: $("#dlgReleaseTime").val().trim(),
        operator: $("#username_apl").val().trim(),
        type_dtl_no: $("#assets_no_apl").val().trim(),
        type_dtl_name: $("#assets_name_apl").val().trim(),
        sizes: $("#sizes_name_apl").val().trim(),
        mon_category_id: mon_category_id,
    });
}

// 导出物资申请excel
function exportMonthlyApplyData() {
    var row_apply = $('#dg').datagrid('getSelected');
    console.log(row_apply);
    var operator = $("#username_apl").val().trim();
    var date_mon = $("#dlgReleaseTime").val().trim();
    if (row_apply == null) {
        U.msg('请先选中');
        return;
    }
    // var apply_man = $("#apply_man_s").val();
    // window.location.href = getRootPath() + '/mtManage/assets/exportApplyData?erp_no=' + erp_no
    //     + '&apply_man=' + apply_man;
    window.location.href = getRootPath() + '/mtManage/assets/exportMonthlyApplyData?mon_category_id=' + mon_category_id +
        "&operator=" + operator + "&mon_date=" + date_mon;
}

//导入上个月数据
function importMonthlyApplyData() {
    var row_apply = $('#dg').datagrid('getSelected');
    console.log(row_apply);
    var operator = $("#username_apl").val().trim();
    var date_mon = $("#dlgReleaseTime").val().trim();
    var date_mon_last_array = date_mon.split("-");
    var date_mon_last;
    if (date_mon_last_array[1] == '1') {
        date_mon_last = (date_mon_last_array[0] - 1) + '-' + '12';
    } else {
        date_mon_last = date_mon_last_array[0] + '-' + (date_mon_last_array[1] - 1);
    }
    if (row_apply == null) {
        U.msg('请先选中');
        return;
    }
    parent.$.messager.confirm('提示', '新增数据(' + date_mon_last + ')会在现有的基础上增加，确定要操作吗？', function (data) {
        if (data) {
            $.ajax({
                type: 'post',
                url: getRootPath() + "/mtManage/assets/importMonthlyApplyData",
                data: {
                    mon_category_id: mon_category_id,
                    mon_date: date_mon,
                    mon_date_last: date_mon_last,
                    operator: username
                },
                success: function (data) {
                    if (data.code == "200") {
                        U.msg("新增成功");
                        $('#assets-dg_mon').datagrid('reload');
                    } else {
                        U.msg("新增失败");
                    }
                },
                complete: function () {

                }
            });
        }
    });
}

//月度申请类型编辑
function edit_monCategory() {
    U.msg('请联系管理员处理');
}

//月度申请类型删除
function remove_monCategory() {
    U.msg('请联系管理员处理');
}

//添加月度种类
function add_monCategory() {
    $("#dlg_monCategory_form").dialog({
        title: '添加月度种类',
        width: 350,
        height: 250,
        maximizable: false,
        modal: true,
        closed: true,
        buttons: [{
            text: '确认',
            iconCls: 'icon-ok',
            handler: function () {
                var isValid = $("#form_monCategory").form('validate');
                if (isValid) {
                    U.post({
                        url: getRootPath() + "/mtManage/assets/add_monCategory",
                        loading: true,
                        data: $('#form_monCategory').serialize(),
                        success: function (data) {
                            if (data.code == 200) {
                                U.msg('添加成功');
                                $("#dlg_monCategory_form").dialog('close');
                                $('#dg').datagrid('load');
                            } else if (data.code == 400) {//参数验证失败
                                U.msg('参数验证失败');
                            } else if (data.code == 409) {
                                U.msg('用户已存在');
                            } else {
                                U.msg('服务器异常');
                            }
                        }
                    });
                }
            }
        }, {
            text: '取消',
            handler: function () {
                $("#dlg_monCategory_form").dialog('close');
            }
        }]
    });
    $("#form_monCategory").form("clear");
    setVal("#completedBy", username);
    $("#dlg_monCategory_form").dialog("open");
}

//双击进去月度申请
function operator_apply(row) {
    setVal("#username_apl", username);
    console.log(row);
    if (row == null) {
        U.msg('请先选中');
        return;
    }

    mon_category_id = row.mon_category_id;
    $("#dlg_monApply").dialog({
        title: '月度申请明细',
        width: 1050,
        height: 500,
        maximizable: true,
        modal: true,
        closed: false,
        buttons: [{
            id: 'submitBtn',
            text: '提交',
            iconCls: 'icon-ok',
            handler: function () {
                var row_dtl = $('#assets-dg_mon').datagrid("getSelected");
                U.post({
                    url: getRootPath() + "/mtManage/assets/submit_monthly_apply",
                    loading: true,
                    // data: "node_seq='-1'&turn_node_seq='1'" +
                    //     "&currentuser=" + username + "&erp_no=" + dgSel.erp_no,
                    data: "operator=" + username + "&mon_category_id=" + mon_category_id +
                        "&mon_date=" + row_dtl.mon_date,
                    success: function (data) {
                        if (data.code == 200) {
                            U.msg('提交成功');
                            $("#dlg_monApply").dialog('close');
                        } else if (data.code == 400) {//参数验证失败
                            U.msg('参数验证失败');
                        } else {
                            U.msg('服务器异常');
                        }
                    }
                });
            }
        }, {
            id: 'checkBtn',
            text: '审核',
            iconCls: 'icon-ok',
            handler: function () {
                U.post({
                    url: getRootPath() + "/mtManage/assets/check_monthly_apply",
                    loading: true,
                    data: "operator=" + username + "&mon_category_id=" + mon_category_id +
                        "&mon_date=" + row_dtl.mon_date + "&operator=" + row_dtl.operator,
                    success: function (data) {
                        if (data.code == 200) {
                            U.msg('审核成功');
                            $("#dlg_monApply").dialog('close');
                        } else if (data.code == 400) {//参数验证失败
                            U.msg('参数验证失败');
                        } else {
                            U.msg('服务器异常');
                        }
                    }
                });
            }
        }, {
            id: 'backBtn',
            text: '打回',
            iconCls: 'icon-ok',
            handler: function () {
                var rs;
                $.messager.prompt("提示:", "请输入打回原因:", function (r) {
                    console.log(r)
                    rs = r;//将打回原因赋值给rs
                    if (rs == "" || rs == null) {
                        U.msg('打回失败，输入内容不能为空');
                        return;
                    } else {
                        U.post({
                            url: getRootPath() + "/mtManage/assets/back_monthly_apply",
                            loading: true,
                            data: "operator=" + username + "&mon_category_id=" + mon_category_id +
                                "&mon_date=" + row_dtl.mon_date + "&operator=" + row_dtl.operator + "&back_rs=" + rs,
                            success: function (data) {
                                if (data.code == 200) {
                                    U.msg('操作成功');
                                    $("#dlg_monApply").dialog('close');
                                } else if (data.code == 400) {//参数验证失败
                                    U.msg('参数验证失败');
                                } else {
                                    U.msg('服务器异常');
                                }
                            }
                        });
                    }
                });
            }
        }],
        onClose: function () {
            $('#dg').datagrid('load');
        }
    });
    var dateNow = new Date();
    var dateStr = dateNow.getFullYear() + "-" + (dateNow.getMonth() + 1);
    setVal("#dlgReleaseTime", dateStr);
    var apply_username = $("#username_apl").val();
    $('#assets-dg_mon').datagrid({
        method: "get",
        url: getRootPath() + '/mtManage/assets/list_monApply',
        fit: true,//让datagrid自适应高度
        border: true,
        idField: 'mon_dtl_id',
        striped: false,
        pagination: true,
        onClickCell: onClickCell,
        onAfterEdit: onAfterEdit,
        rownumbers: true,
        pageNumber: 1,
        pageSize: 20,
        pageList: [10, 20, 30, 50, 100],
        singleSelect: true,
        checkOnSelect: true,
        fitColumns: false,
        toolbar: '#tb_apply_mon',
        columns: [[
            {field: 'ck', checkbox: true},
            {
                field: 'operate', title: '选择物资', align: 'center', width: 80,//应该是任意写的一个field，数据库中没对应字段
                formatter: function (value, row, index) {
                    var e = "<a onclick='getAssets(" + row.mon_dtl_id + "," + index + ")' class='button-edit button-blue'>选择</a>";
                    return e;
                }
            },
            {field: 'type_dtl_no', title: '物资编号', width: 100},
            {field: 'k3_code', title: 'K3编码', width: 100},
            {field: 'type_dtl_name', title: '物资名称', width: 100},
            {field: 'sizes', title: '规格', width: 100},
            {field: 'operator', title: '申请人', width: 100},
            {field: 'apply_num', editor: 'text', title: '本次申请数量', width: 80},
            {field: 'applied_num', title: '已申请数量', width: 80},
            {field: 'stockin_num', title: '库存数量', width: 70},
            {field: 'apply_type', editor: 'text', title: '申购类别', width: 50},
            {field: 'unit', title: '单位', width: 50},
            {field: 'apply_reason', editor: 'text', title: '申请原因', width: 100},
            {
                field: 'check_flag', title: '已确认完毕', width: 100,
                formatter: function (value, row, index) {
                    if (value == '999') {
                        return "<span title='已确认OK'>已确认OK</span>";
                    } else if (value == '1') {
                        return "<span title='已提交'>已提交</span>";
                    } else if (value == '0') {
                        return "<span title='未提交'>未提交</span>";
                    } else if (value == '-1') {
                        return "<span title='打回'>未提交</span>";
                    }
                }
            },
            {
                field: 'remark', editor: 'text', title: '备注', width: 100,
                formatter: function (value, row, index) {
                    if (value == null) {
                        return "<span title=''>" + "" + "</span>";
                    } else {
                        return "<span title='" + value + "'>" + value + "</span>";
                    }
                }
            }
            // {field: 'mon_date', title: '年月日期', width: 100},
            // {field: 'operator', title: '操作人', width: 100},
            // {field: 'operator_time', title: '操作时间', width: 100}
        ]],
        onLoadSuccess: function (data) {
            $('.button-edit').linkbutton({
                plain: true
            });

            $('#assets-dg_mon').datagrid("selectRow", 0);
            var row_dtl = $('#assets-dg_mon').datagrid("getSelected");
            if (row_dtl == null || apply_username == "") {
                $("#submitBtn").hide();
                $("#checkBtn").hide();
                $("#backBtn").hide();
            } else {
                if (row_dtl.check_flag == "1") {
                    $("#submitBtn").hide();
                } else if (row_dtl.check_flag == "0" || row_dtl.check_flag == "-1") {
                    $("#checkBtn").hide();
                    $("#backBtn").hide();
                } else if (row_dtl.check_flag == null) {
                    $("#checkBtn").hide();
                    $("#backBtn").hide();
                } else {
                    $("#submitBtn").hide();
                    $("#checkBtn").hide();
                    $("#backBtn").hide();
                }
                if (username != "石朋辉") {
                    $("#checkBtn").hide();
                    $("#backBtn").hide();
                }
                if (apply_username != username) {
                    $("#submitBtn").hide();
                    $("#checkBtn").hide();
                    $("#backBtn").hide();
                }
            }
        },
        queryParams: {
            "mon_date": dateStr,
            "operator": apply_username,
            "mon_category_id": mon_category_id
        },
        onDblClickRow: function (index, row) {

        }
    });
    initGridHeight("#assets-dg_mon");//datagrid自适应高度
}

//添加一条记录
function add_monApply() {
    var row = $('#assets-dg_mon').datagrid('getSelected');
    var mon_date;
    if (row != null) {
        if (row.check_flag != '0' && row.check_flag != '-1') {
            U.msg("当前订单已提交不能修改");
            return;
        } else {
            mon_date = row.mon_date;
        }
    } else {
        mon_date = $("#dlgReleaseTime").val();
    }
    $.ajax({
        type: 'post',
        url: getRootPath() + "/mtManage/assets/addMonApplyInfo_NULL",
        data: {
            mon_category_id: mon_category_id,
            mon_date: mon_date,
            operator: username
        },
        success: function (data) {
            $('#assets-dg_mon').datagrid('reload');
        },
        complete: function () {

        }
    });
}

//删除一条记录
function del_monApply() {
    var row = $('#assets-dg_mon').datagrid('getSelected');
    if (row == null) {
        U.msg('请先选中');
        return;
    }

    if (row.check_flag == "0" && row.operator == username) {

        parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function (data) {
            if (data) {
                U.post({
                    url: getRootPath() + "/mtManage/assets/del_monApply",
                    loading: true,
                    data: {mon_dtl_id: row.mon_dtl_id},
                    success: function (data) {
                        if (data.code == 200) {
                            U.msg('删除成功');
                            row.length = 0;
                            $("#assets-dg_mon").datagrid('load');
                        } else if (data.code == 400) {//参数验证失败
                            U.msg('参数验证失败');
                        } else if (data.code == 404) {
                            U.msg('未找到该用户');
                        } else {
                            U.msg('服务器异常');
                        }
                    }
                });
            }
        });
    } else {
        U.msg("当前流程已审核或不是申请人，不能进行修改或删除")
    }
}

//获取选择的物资
function getAssets(mon_dtl_id, index) {
    $("#assets-dg_mon").datagrid("selectRow", index);
    var row = $("#assets-dg_mon").datagrid("getSelected");
    if (row.check_flag != '0' && row.check_flag != '-1') {
        U.msg("当前订单已提交，不能修改");
        return;
    }
    setVal("#typeNo_dlg", "");
    setVal("#assets_name", "");
    dialog_assets = $("#dlg_assets").dialog({
        title: '选择物资',
        width: 800,
        height: 350,
        maximizable: false,
        modal: true
    });

    $('#assets-dg').datagrid({
        method: "post",
        url: getRootPath() + '/mtManage/assets/list_Detail',
        fit: true,
        fitColumns: true,
        border: true,
        idField: 'type_dtl_id',
        striped: false,
        pagination: false,
        rownumbers: true,
        pageNumber: 1,
        pageSize: 20,
        pageList: [10, 20, 30, 50, 100],
        singleSelect: false,
        selectOnCheck: true,
        checkOnSelect: true,
        columns: [[
            {field: 'ck', checkbox: true},
            {field: 'type_dtl_id', title: 'id', hidden: true},
            {field: 'type_dtl_name', title: '物资名称', sortable: false, width: 25},
            {field: 'k3_code', title: 'K3编码', sortable: false, width: 25},
            {field: 'type_dtl_no', title: '物资编号', sortable: false, width: 25},
            {field: 'model', title: '物资型号', sortable: false, width: 25},
            {field: 'sizes', title: '物资规格', sortable: false, width: 25},
            {field: 'type_main_id', title: '主分类id', hidden: true},
            {field: 'dept_name', title: '部门', hidden: true},
            {field: 'type_main_name', title: '分类名称', sortable: false, width: 25}
            // {
            //     field: 'operate', title: '操作', width: 100,
            //     formatter: function (value, row, index) {
            //         var d = "<a onclick='remove_flow(" + row.id + ")' class='button-delete button-red'>删除</a>";
            //         var e = "<a onclick='edit_flow(" + row.id + ")' class='button-edit button-blue'>编辑</a>";
            //         var r = "<a onclick='getOperator(" + row.id + ")' class='button-edit button-teal'>操作员配置</a>";
            //         if (row.serial_flag == '2') {//物资申请
            //             return e + '  ' + d;
            //         } else {
            //             return e + '  ' + d + '  ' + r;
            //         }
            //     }
            //
            // }
        ]],
        // onLoadSuccess: function (data) {
        //     $('.button-delete').linkbutton({});
        //     $('.button-edit').linkbutton({});
        // },
        queryParams: {
            "typeMainId": ''
        },
        onDblClickRow: function (index, row) {
            var sto_num;
            var applied_num;
            //对库存数量进行赋值
            U.post({
                url: getRootPath() + "/mtManage/assets/getStockinNumAndAppliedNum",
                loading: true,
                async: false,//同步
                data: {
                    type_dtl_no: row.type_dtl_no,
                    mon_dtl_id: mon_dtl_id,
                    type_dtl_id: row.type_dtl_id
                },
                success: function (data) {
                    if (data.code == 200) {
                        var stockinNum = data.data[0];
                        var appliedNum = data.data[1];
                        if (stockinNum == null) {
                            sto_num = '0';
                        } else {
                            sto_num = stockinNum.stockin_num;
                        }
                        if (appliedNum == null) {
                            applied_num = "0";
                        } else {
                            applied_num = appliedNum.applied_num;
                        }

                    } else if (data.code == 400) {//参数验证失败
                        U.msg('参数验证失败');
                    } else if (data.code == 409) {
                        U.msg('');
                    } else {
                        U.msg('服务器异常');
                    }
                }
            });
            U.post({
                url: getRootPath() + "/mtManage/assets/add_assetsinfo",
                loading: true,
                async: false,//同步
                data: {
                    mon_dtl_id: mon_dtl_id,
                    type_dtl_id: row.type_dtl_id,
                    stockin_num: sto_num,
                    applied_num: applied_num
                },
                success: function (data) {
                    if (data.code == 200) {
                        U.msg('更新成功');
                    } else if (data.code == 400) {//参数验证失败
                        U.msg('参数验证失败');
                    } else if (data.code == 409) {
                        U.msg('');
                    } else {
                        U.msg('服务器异常');
                    }
                }
            });
            dialog_assets.dialog('close');
            $('#assets-dg_mon').datagrid('load');
        }
    });
}

//查询物资
function queryAssets() {
    var typeNo = $("#typeNo_dlg").val().trim();
    var typeName = $("#assets_name").val().trim();
    var typeSizes = $("#sizes_name").val().trim();
    $('#assets-dg').datagrid('reload', {
        type_dtl_no: typeNo,
        type_dtl_name: typeName,
        sizes:typeSizes
    });
}

//将datagrid设置成高度自适应
function initGridHeight(obj) {
    if (obj != null) {
        $(window).on("resize", function () {
            try {
                var win_h = $(window).height();
                var height = Math.floor(win_h * 0.95);
                var options = $(obj).datagrid('options');
                if (options != null) {
                    if (options.fit) {
                        $(obj).parents("div.datagrid-wrap:first").css({
                            height: height + 'px'
                        });
                        $(obj).datagrid("resize");
                    }
                }
            } catch (e) {
                return false;
            }
        }).trigger("resize");
    }
}

//解决双击新增的相关操作---
var editIndex = undefined;

function endEditing() {//该方法用于关闭上一个焦点的editing状态
    if (editIndex == undefined) {
        return true
    }
    if ($('#assets-dg_mon').datagrid('validateRow', editIndex)) {
        $('#assets-dg_mon').datagrid('endEdit', editIndex);
        editIndex = undefined;
        return true;
    } else {
        return false;
    }
}

//点击单元格事件：
function onClickCell(index, field, value) {
    $('#assets-dg_mon').datagrid("selectRow", index);
    if (endEditing()) {
        if (field == "apply_num" || field == "apply_type" || field == "apply_reason" || field == "remark") {
            $(this).datagrid('beginEdit', index);
            var ed = $(this).datagrid('getEditor', {index: index, field: field});
            $(ed.target).focus();
        }
        editIndex = index;
    }
    // $('#assets-dg_mon').datagrid('onClickRow');//这句没啥用
}

//单元格失去焦点执行的方法
function onAfterEdit(index, row, changes) {
    if (row.check_flag != '0' && row.check_flag != '-1') {
        U.msg("表单已提交，不允许修改");
        $("#assets-dg_mon").datagrid('reload');
        return;
    }
    var updated = $('#assets-dg_mon').datagrid('getChanges', 'updated');
    if (updated.length < 1) {
        editRow = undefined;
        $('#assets-dg_mon').datagrid('unselectAll');
        return;
    } else {
        // 传值
        submitForm(index, row, changes);
    }
}

//提交数据
function submitForm(index, row, changes) {
    var apply_num = row.apply_num;
    var apply_type = row.apply_type;
    var apply_reason = row.apply_reason;
    var remark = row.remark;
    var mon_dtl_id = row.mon_dtl_id;
    var r = /^-?[1-9]/;
    if (!r.test(apply_num)) {
        $.messager.alert('提醒', '请输入正整数！');
        return;
    }
    parent.$.messager.confirm('提示', '确认修改数据吗？', function (data) {
        if (data) {
            $.ajax({
                type: "post",
                async: false,
                url: getRootPath() + "/mtManage/assets/update_monApplyInfo",
                data: {
                    "apply_num": apply_num,
                    "apply_type": apply_type,
                    "apply_reason": apply_reason,
                    "remark": remark,
                    "mon_dtl_id": mon_dtl_id
                },
                success: function (data) {
                    if (data.code == "200") {
                        //alert("保存成功");
                        // $("#assets-dg_mon").datagrid('reload');
                        U.msg('申请数量更新成功');
                    }
                }
            });
            var sto_num;
            var applied_num;
            //对库存数量进行赋值
            U.post({
                url: getRootPath() + "/mtManage/assets/getStockinNumAndAppliedNum",
                loading: true,
                async: false,//同步
                data: {
                    type_dtl_no: row.type_dtl_no,
                    mon_dtl_id: mon_dtl_id,
                    type_dtl_id: row.type_dtl_id
                },
                success: function (data) {
                    if (data.code == 200) {
                        var stockinNum = data.data[0];
                        var appliedNum = data.data[1];
                        if (stockinNum == null) {
                            sto_num = '0';
                        } else {
                            sto_num = stockinNum.stockin_num;
                        }
                        if (appliedNum == null) {
                            applied_num = "0";
                        } else {
                            applied_num = appliedNum.applied_num;
                        }

                    } else if (data.code == 400) {//参数验证失败
                        U.msg('参数验证失败');
                    } else if (data.code == 409) {
                        U.msg('');
                    } else {
                        U.msg('服务器异常');
                    }
                }
            });
            U.post({
                url: getRootPath() + "/mtManage/assets/add_assetsinfo",
                loading: true,
                async: false,//同步
                data: {
                    mon_dtl_id: mon_dtl_id,
                    type_dtl_id: row.type_dtl_id,
                    stockin_num: sto_num,
                    applied_num: applied_num
                },
                success: function (data) {
                    if (data.code == 200) {
                        U.msg('更新成功');
                    } else if (data.code == 400) {//参数验证失败
                        U.msg('参数验证失败');
                    } else if (data.code == 409) {
                        U.msg('');
                    } else {
                        U.msg('服务器异常');
                    }
                }
            });
        }
        $("#assets-dg_mon").datagrid('reload');
    });

}

// ---

//重写datebox,让其只显示年月-----
$('#dlgReleaseTime').datebox({
    onShowPanel: function () {//显示日趋选择对象后再触发弹出月份层的事件，初始化时没有生成月份层
        span.trigger('click'); //触发click事件弹出月份层
        if (!tds)
            setTimeout(function () { //延时触发获取月份对象，因为上面的事件触发和对象生成有时间间隔
                tds = p.find('div.calendar-menu-month-inner td');
                tds.click(function (e) {
                    e.stopPropagation(); //禁止冒泡执行easyui给月份绑定的事件
                    var year = /\d{4}/.exec(span.html())[0] //得到年份
                        , month = parseInt($(this).attr('abbr'), 10); //月份 之前是这样的month = parseInt($(this).attr('abbr'), 10) + 1;
                    $('#dlgReleaseTime').datebox('hidePanel') //隐藏日期对象
                        .datebox('setValue', year + '-' + month); //设置日期的值
                });
            }, 0);
    },
    parser: function (s) {//配置parser，返回选择的日期
        if (!s) return new Date();
        var arr = s.split('-');
        return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
    },
    formatter: function (d) {
        return d.getFullYear() + '-' + (d.getMonth() + 1);
    }//配置formatter，只返回年月 之前是这样的d.getFullYear() + '-' +(d.getMonth());
});

var p = $('#dlgReleaseTime').datebox('panel'), //日期选择对象
    tds = false, //日期选择对象中月份
    span = p.find('span.calendar-text'); //显示月份层的触发控件
var curr_time = new Date();
$("#dlgReleaseTime").datebox("setValue", myformatter(curr_time));//设置前当月

//格式化日期
function myformatter(date) {
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
//var d = 1;
    return y + '-' + (m < 10 ? ('0' + m) : m);//+ '-' + (d < 10 ? ('0' + d) : d);

}

// ----
